/*
 * bill_test.c
 *
 *  Created on: Apr 22, 2011
 *      Author: Gilad & Yotam
 */
#include "../bill.h"
#include "test_utilities.h"
#include "../car.h"
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>

bool test_billCreateNewElement() {
	Car gilad = carCreate(123, "Gilad", 11, 6);
	BillElement billGilad = billCreateNewElement(gilad, 80);
	ASSERT_TEST(billGilad != NULL);
	ASSERT_TEST(billGetCarLicense(billGilad) == 123);
	ASSERT_TEST(strcmp(billGetCarName(billGilad), "Gilad") == 0);
	ASSERT_TEST(billGetKmDrove(billGilad) == 80);
	ASSERT_TEST(billGetPricePerKm(billGilad) == 11);
	ASSERT_TEST(billGetPrice(billGilad) == (11*80));
	ASSERT_TEST(billGetCarSaleStatus(billGilad) == false);

	freeBillElement(billGilad);

	carSale(gilad, 20, 30, 200);
	billGilad = billCreateNewElement(gilad, 22);
	ASSERT_TEST(billGetCarLicense(billGilad) == 123);
	ASSERT_TEST(strcmp(billGetCarName(billGilad), "Gilad") == 0);
	ASSERT_TEST(billGetKmDrove(billGilad) == 22);
	ASSERT_TEST(billGetPricePerKm(billGilad) == 11);
	ASSERT_TEST(billGetPrice(billGilad) == 200);
	ASSERT_TEST(billGetCarSaleStatus(billGilad) == true);

	freeBillElement(billGilad);
	carFree(gilad);

	return true;
}
bool test_copyBillElement() {
	Car yotam = carCreate(111, "Yotam", 10, 12);
	BillElement billYotam = billCreateNewElement(yotam, 50);
	BillElement billCopy = copyBillElement(billYotam);
	ASSERT_TEST(billYotam != billCopy);
	ASSERT_TEST(billGetCarLicense(billCopy) == 111);
	ASSERT_TEST(strcmp(billGetCarName(billCopy), "Yotam") == 0);
	ASSERT_TEST(billGetKmDrove(billCopy) == 50);
	ASSERT_TEST(billGetPricePerKm(billCopy) == 10);
	ASSERT_TEST(billGetPrice(billCopy) == 500);
	ASSERT_TEST(billGetCarSaleStatus(billCopy) == false);

	freeBillElement(billYotam);
	freeBillElement(billCopy);

	carSale(yotam, 33, 55, 300);

	billYotam = billCreateNewElement(yotam, 40);
	billCopy = copyBillElement(billYotam);

	ASSERT_TEST(billYotam != billCopy);
	ASSERT_TEST(billGetCarLicense(billCopy) == 111);
	ASSERT_TEST(strcmp(billGetCarName(billCopy), "Yotam") == 0);
	ASSERT_TEST(billGetKmDrove(billCopy) == 40);
	ASSERT_TEST(billGetPricePerKm(billCopy) == 10);
	ASSERT_TEST(billGetPrice(billCopy) == 300);
	ASSERT_TEST(billGetCarSaleStatus(billCopy) == true);

	freeBillElement(billYotam);
	freeBillElement(billCopy);
	carFree(yotam);

	return true;
}

bool test_billGetCarLicense() {
	Car car = carCreate(-256, "Mazda'le", 30, 704);
	BillElement carBill = billCreateNewElement(car, 40);
	ASSERT_TEST(billGetCarLicense(carBill) == -256);

	freeBillElement(carBill);
	carFree(car);
	return true;
}
bool test_billGetCarName() {
	Car car = carCreate(22, "ToYoti", 100, 0);
	BillElement carBill = billCreateNewElement(car, 12);
	ASSERT_TEST(strcmp(billGetCarName(carBill), "ToYoti") == 0);

	freeBillElement(carBill);
	carFree(car);
	return true;
}
bool test_billGetKmDrove() {
	Car car = carCreate(555, "Suzukish", 5, 100);
	BillElement carBill = billCreateNewElement(car, 50);
	ASSERT_TEST(billGetKmDrove(carBill) == 50);

	freeBillElement(carBill);
	carFree(car);
	return true;
}
bool test_billGetPricePerKm() {
	Car car = carCreate(2000, "Honda S", 14, 302);
	BillElement carBill = billCreateNewElement(car, 10);
	ASSERT_TEST(billGetPricePerKm(carBill) == 14);

	freeBillElement(carBill);
	carFree(car);
	return true;
}
bool test_billCarSaleStatus() {
	Car car = carCreate(100, "Bimba", 200, 59999);
	carSale(car, 2, 70, 1);
	BillElement carBill = billCreateNewElement(car, 80);
	ASSERT_TEST(billGetCarSaleStatus(carBill) == false);

	freeBillElement(carBill);

	carBill = billCreateNewElement(car, 70);
	ASSERT_TEST(billGetCarSaleStatus(carBill) == true);

	freeBillElement(carBill);
	carFree(car);
	return true;
}
bool test_billGetPrice() {
	Car car = carCreate(666, "Bugatti Veyron", 1001, 0);
	carSale(car, 5, 10, 5000);
	BillElement carBill = billCreateNewElement(car, 3);
	ASSERT_TEST(billGetPrice(carBill) == 3003);

	freeBillElement(carBill);

	carBill = billCreateNewElement(car, 5);
	ASSERT_TEST(billGetPrice(carBill) == 5000);

	freeBillElement(carBill);
	carFree(car);
	return true;
}
bool test_freeBillElement() {
	/*tested via valgrind*/
	return true;
}

int main() {
	RUN_TEST(test_billCreateNewElement);
	RUN_TEST(test_copyBillElement);
	RUN_TEST(test_billGetCarLicense);
	RUN_TEST(test_billGetCarName);
	RUN_TEST(test_billGetKmDrove);
	RUN_TEST(test_billGetPricePerKm);
	RUN_TEST(test_billCarSaleStatus);
	RUN_TEST(test_billGetPrice);
	RUN_TEST(test_freeBillElement);

	return 0;
}
